/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Netz;

/**
 * Hier kann der Spieler festlegen ob er sich autozuweisen lassen will oder einfach einenj Spieler einladen will.
 * @author Daniel Mueller, Phillip Hertel, Jonas Hauff
 */
public class Lobbys extends javax.swing.JFrame {

    private NetzeClient client;
    private ClientStart vorgaenger;
    private Spielersuche auto;
    private Netze spiel;
    /**
     * Creates new form Lobbys
     */
    public Lobbys() {
        initComponents();
    }
    /**
     * Der Client wird festgelegt, um später pSend vom Client abzurufen.
     * @param pClient 
     */
    public void setClient(NetzeClient pClient)
    {
        client = pClient;
    }
    /**
     * Verstellt das Label für den Namen des aktuellen Spielers nach dem Namen im Parameter.
     * @param pName 
     */
    public void setpName(String pName)
    {
        jLabelName.setText(pName);
    }
    /**
     * Übergibt der Lobby das Startfenster, damit später bei beenden auf dieses Fenster zurückgeschaltet wird.
     * @param pVor 
     */
    public void setVorgaenger(ClientStart pVor)
    {
        vorgaenger = pVor;
    }
    /**
     * Die Lobby wird geschlossen und ein Spiel gestartet.
     * @return spiel der Klasse Netze
     */
    public Netze spielStarten()
    {
        spiel = new Netze();
        spiel.setVisible(true);
        spiel.setClient(client);
        spiel.setLobby(this);
        this.setVisible(false);
        if(auto != null)
        {
            auto.setVisible(false);
        }
        return spiel;
    }
    /**
     * Die Spielerliste wird aktualisiert.
     * @param pSpieler 
     */
    public void spielerlisteAkt(String pSpieler)
    {
        jTextAreaSpieler.setText(pSpieler);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jLabelueberschrift = new javax.swing.JLabel();
        jLabel = new javax.swing.JLabel();
        jButtonherausfordern = new javax.swing.JButton();
        jButtonAuto = new javax.swing.JButton();
        jLabelangemeldetals = new javax.swing.JLabel();
        jButtonStats = new javax.swing.JButton();
        jLabelName = new javax.swing.JLabel();
        jButtonBeenden = new javax.swing.JButton();
        jTextFieldSpielername = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaSpieler = new javax.swing.JTextArea();
        jButtonChat = new javax.swing.JButton();
        jButtonAktu = new javax.swing.JButton();

        jMenu1.setText("jMenu1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelueberschrift.setText("TicTacToe - Online");

        jLabel.setText("Folgender Spieler sind online:");

        jButtonherausfordern.setText("herausfordern");
        jButtonherausfordern.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonherausfordernActionPerformed(evt);
            }
        });

        jButtonAuto.setText("Autozuweisung");
        jButtonAuto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAutoActionPerformed(evt);
            }
        });

        jLabelangemeldetals.setText("Du bist angemeldet als:");

        jButtonStats.setText("Meine Statistiken");
        jButtonStats.setEnabled(false);

        jLabelName.setText("pName");

        jButtonBeenden.setText("Beenden");
        jButtonBeenden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBeendenActionPerformed(evt);
            }
        });

        jTextFieldSpielername.setText("Spielername");

        jScrollPane2.setHorizontalScrollBar(null);

        jTextAreaSpieler.setColumns(20);
        jTextAreaSpieler.setRows(5);
        jTextAreaSpieler.setFocusable(false);
        jScrollPane2.setViewportView(jTextAreaSpieler);

        jButtonChat.setText("Chat");
        jButtonChat.setEnabled(false);

        jButtonAktu.setText("Aktualisieren");
        jButtonAktu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAktuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jTextFieldSpielername, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButtonChat, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonAuto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonStats, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelangemeldetals, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonBeenden, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 141, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButtonAktu, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jButtonherausfordern, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addComponent(jLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(26, 26, 26))
            .addGroup(layout.createSequentialGroup()
                .addGap(194, 194, 194)
                .addComponent(jLabelueberschrift)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabelueberschrift)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel)
                    .addComponent(jLabelangemeldetals)
                    .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonAuto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonStats)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonChat)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonBeenden, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonAktu)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonherausfordern)
                    .addComponent(jTextFieldSpielername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * Es wird an den Server gesendet, dass der Spieler autozugewiesen werden will 
     * und das Fenster fuer die Autozuweisung wird geoeffnet.
     * @param evt 
     */
    private void jButtonAutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAutoActionPerformed
        client.pSend("Autozuweisung");
        auto = new Spielersuche();
        auto.setVisible(true);
        auto.setLobby(this);
        auto.setClient(client);
        this.setVisible(false);
        
        
    }//GEN-LAST:event_jButtonAutoActionPerformed
    /**
     * Die Lobby wird geschlossen und das Startfenster geoeffnet.
     * @param evt 
     */
    private void jButtonBeendenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBeendenActionPerformed
        this.setVisible(false);
        vorgaenger.setVisible(true);
        client.beenden();
    }//GEN-LAST:event_jButtonBeendenActionPerformed
    /**
     * Es wird an den Server geschickt, dass der eingegebene Spieler herausgefordert werden soll.
     * @param evt 
     */
    private void jButtonherausfordernActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonherausfordernActionPerformed
        client.pSend("Spieler herausfordern: "+ jTextFieldSpielername.getText());
    }//GEN-LAST:event_jButtonherausfordernActionPerformed
    /**
     * Es wird an den Server gesendet, dass die Spielerliste akt. werden soll.
     * @param evt 
     */
    private void jButtonAktuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAktuActionPerformed
        client.pSend("Aktualisieren");
    }//GEN-LAST:event_jButtonAktuActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Lobbys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Lobbys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Lobbys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Lobbys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Lobbys().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAktu;
    private javax.swing.JButton jButtonAuto;
    private javax.swing.JButton jButtonBeenden;
    private javax.swing.JButton jButtonChat;
    private javax.swing.JButton jButtonStats;
    private javax.swing.JButton jButtonherausfordern;
    private javax.swing.JLabel jLabel;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JLabel jLabelangemeldetals;
    private javax.swing.JLabel jLabelueberschrift;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextAreaSpieler;
    private javax.swing.JTextField jTextFieldSpielername;
    // End of variables declaration//GEN-END:variables
}
